/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dahg.project.istu.controller.model;

import com.dahg.project.istu.controller.bean.commons.ICatalogo;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

/**
 *
 * @author Jose
 */
@Entity
@Table(name = "rol")
public class Rol implements ICatalogo {
    
    @Id
    private String codigo;
    private String nombre;
    
    @ManyToMany
    @JoinTable(name="menu_rol",
         joinColumns={@JoinColumn(name="fk_rol")},
         inverseJoinColumns={@JoinColumn(name="fk_menu")})
    @LazyCollection(LazyCollectionOption.TRUE)
    @OrderBy("padre,id")
    private List<Menu> menus;

    public String getCodigo() {
        return codigo;
    }

    public void setCodigo(String codigo) {
        this.codigo = codigo;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public List<Menu> getMenus() {
        return menus;
    }

    public void setMenus(List<Menu> menus) {
        this.menus = menus;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Rol other = (Rol) obj;
        return !((this.codigo == null) ? (other.codigo != null) : !this.codigo.equals(other.codigo));
    }

    @Override
    public Object getPrimaryKey() {
        return getCodigo();
    }
    
    
}
